package com.gzist.springailab07.agent;

import com.gzist.springailab07.advisor.MyLoggerAdvisor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.stereotype.Component;

/**
 * AI 超级智能体（拥有自主规划能力，可以直接使用）
 */
@Component
public class LeiMuManus extends ToolCallAgent {

    public LeiMuManus(ToolCallback[] allTools, ChatModel dashscopeChatModel) {
        super(allTools);
        this.setName("leimuManus");
        String SYSTEM_PROMPT = """
                You are leimuManus, an all-capable AI assistant, aimed at solving any task presented by the user.
                You have various tools at your disposal that you can call upon to efficiently complete complex requests.
                """;
        this.setSystemPrompt(SYSTEM_PROMPT);
        String NEXT_STEP_PROMPT = """
                Based on user needs, proactively select the most appropriate tool or combination of tools.
                For complex tasks, you can break down the problem and use different tools step by step to solve it.
                After using each tool, clearly explain the execution results and suggest the next steps.
                If you want to stop the interaction at any point, use the `terminate` tool/function call.
                """;
        this.setNextStepPrompt(NEXT_STEP_PROMPT);
        String FINAL_SYSTEM_PROMPT = """
                You are a "Task Summary Expert". \s
                - Generate a detailed and well-structured final answer based on the complete conversation history and tool execution results. \s
                - For query-type tasks, list all key information, data, and conclusions; for action-type tasks, highlight the outcomes and impacts. \s
                - Do not invoke any additional tools or include redundant content such as “next steps”. \s
                - Tone: objective, comprehensive, and easy for the user to understand.""";
        this.setFinalSystemPrompt(FINAL_SYSTEM_PROMPT);
        String FINAL_USER_PROMPT = "Please synthesize all the above information to produce the final comprehensive answer or summary for the user. Do not invoke any tools.";
        this.setFinalUserPrompt(FINAL_USER_PROMPT);
        this.setMaxSteps(20);
        // 初始化 AI 对话客户端
        ChatClient chatClient = ChatClient.builder(dashscopeChatModel)
                .defaultAdvisors(new MyLoggerAdvisor())
                .build();
        this.setChatClient(chatClient);
    }
}
